package middleware

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/common"
	"log"
	"net/http"
	"net/http/httputil"
)

func LogMiddleware(next common.Endpoint) common.Endpoint {
	return func(ctx context.Context, req *http.Request) (resp *http.Response, err error) {

		reqLog, _ := httputil.DumpRequest(req, true)
		log.Println(string(reqLog))

		resp, err = next(ctx, req)
		if err != nil {
			return
		}

		respLog, _ := httputil.DumpResponse(resp, true)
		log.Println(string(respLog))

		return
	}
}
